@extends("layouts.backend.webadmin")
@section('page-header')
<h1>
    <small>config</small>
</h1>
@endsection

@section('content')
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">

            <div class="box">

                <div class="box-body">
                    <ul class="nav nav-tabs">
                        <li role="presentation" @if(old('type')=='' || old('type')==1)class="active"@endif><a href="#">基本设置</a></li>
                        <li role="presentation" @if(old('type')==2)class="active"@endif><a href="#">邮箱设置</a></li>
                        <li role="presentation" @if(old('type')==3)class="active"@endif><a href="#">漏洞分发</a></li>
                        {{--<li role="presentation"><a href="#">安全设置</a></li>--}}
                    </ul>
                    @if($errors->any())
                        <ul class="alert alert-danger">
                            @foreach($errors->all() as $error)
                                <li>{{ $error }}</li>
                            @endforeach
                        </ul>
                    @endif
                    <form class="navbar-left " @if(old('type')!='' && old('type')!=1) hidden @endif method="post" action="{{ URL::route('admin.config.set') }}">
                        <div class="form-group">
                            <label for="name">网站名称</label>
                            <input value="@if(isset($baseInfo['name'])){{$baseInfo['name']}}@endif" name="sysconfig[base][name]" type="text" class="form-control" placeholder="Name">
                        </div>
                        <div class="form-group">
                            <label for="address">网站地址</label>
                            <input value="@if(isset($baseInfo['address'])){{$baseInfo['address']}}@endif" name="sysconfig[base][address]" type="text" class="form-control" placeholder="Address">
                        </div>
                        <div class="form-group">
                            <label for="delay_times">延时申请次数</label>
                            <input value="@if(isset($baseInfo['delay_times'])){{$baseInfo['delay_times']}}@endif" name="sysconfig[base][delay_times]" type="text" class="form-control" placeholder="Delay_times">
                        </div>
                        <div class="form-group">
                            <label for="set_top_num">置顶条数</label>
                            <input value="@if(isset($baseInfo['set_top_num'])){{$baseInfo['set_top_num']}}@endif" name="sysconfig[base][set_top_num]" type="text" class="form-control" placeholder="Set_top_num">
                        </div>
                        <div class="form-group">
                            <div class="checkbox">
                                <label>
                                    <input name="sysconfig[base][debug]" type="checkbox" @if(isset($baseInfo['debug'])) checked @endif> 启用debug
                                </label>
                            </div>
                        </div>
                        <input type="hidden" name="type" value="1">
                        {!! csrf_field() !!}
                        <button type="submit" class="btn btn-primary sysconfig-set">提交</button>
                    </form>
                    <form class="navbar-left " @if(old('type')!=2) hidden @endif method="post" action="{{ URL::route('admin.config.set') }}">
                        {{--<div class="form-group">
                            <label for="driver">发送模式</label>

                            <input value="@if(isset($emailInfo['driver'])){{$emailInfo['driver']}}@endif" name="sysconfig[email][driver]" type="text" class="form-control" placeholder="Driver">
                        </div>
                        <div class="form-group">
                            <label for="server">服务器</label>
                            <input value="@if(isset($emailInfo['server'])){{$emailInfo['server']}}@endif" name="sysconfig[email][server]" type="text" class="form-control" placeholder="Server">
                        </div>
                        <div class="form-group">
                            <label for="port">端口</label>
                            <input value="@if(isset($emailInfo['port'])){{$emailInfo['port']}}@endif" name="sysconfig[email][port]" type="text" class="form-control" placeholder="Port">
                        </div>--}}

                        <div class="form-group">
                            <label for="cc">抄送人</label>
                            <input value="@if(isset($emailInfo['cc'])){{$emailInfo['cc']}}@endif" name="sysconfig[email][cc]" type="text" class="form-control" placeholder="Cc">
                        </div>

                        <div class="form-group">
                            <label>发送类型</label>
                            <div class="radio rcp-type">
                                <label>
                                    <input type="radio" value="1" name="sysconfig[email][rcp_type]" @if(isset($emailInfo['rcp_type']) && $emailInfo['rcp_type']==1) checked @endif>
                                    指定用户
                                </label>
                                <div class="row rcp-default" @if(isset($emailInfo['rcp_type']) && $emailInfo['rcp_type']==1) style="display: block;" @else style="display:none;" @endif>
                                    <div class="col-xs-4">
                                        <input value="@if(isset($emailInfo['rcp_default'])) {{$emailInfo['rcp_default']}} @endif" name="sysconfig[email][rcp_default]" type="text" class="form-control" placeholder="Rcp_default">
                                    </div>
                                </div>
                            </div>
                            <div class="radio rcp-type">
                                <label>
                                    <input type="radio" value="2" name="sysconfig[email][rcp_type]" @if(isset($emailInfo['rcp_type']) && $emailInfo['rcp_type']==2) checked @endif>
                                    应用联系人
                                </label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label>即将超时提醒<span style="color: red;">(左到右严重高危低危)</span></label>
                            <div class="row">
                                <div class="col-xs-2">
                                    <input value="@if(isset($emailInfo['istimeout']['serious'])){{$emailInfo['istimeout']['serious']}}@endif" name="sysconfig[email][istimeout][serious]" type="text" class="form-control" placeholder="Serious">
                                </div>
                                <div class="col-xs-2">
                                    <input value="@if(isset($emailInfo['istimeout']['ishighrisk'])){{$emailInfo['istimeout']['ishighrisk']}}@endif" name="sysconfig[email][istimeout][ishighrisk]" type="text" class="form-control" placeholder="Ishighrisk">
                                </div>
                                <div class="col-xs-2">
                                    <input value="@if(isset($emailInfo['istimeout']['low'])){{$emailInfo['istimeout']['low']}}@endif" name="sysconfig[email][istimeout][low]" type="text" class="form-control" placeholder="Low">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label>超时提醒<span style="color: red;">(左到右严重高危低危)</span></label>
                            <div class="row">
                                <div class="col-xs-2">
                                    <input value="@if(isset($emailInfo['hastimeout']['serious'])){{$emailInfo['hastimeout']['serious']}}@endif"  name="sysconfig[email][hastimeout][serious]" type="text" class="form-control" placeholder="Serious">
                                </div>
                                <div class="col-xs-2">
                                    <input value="@if(isset($emailInfo['hastimeout']['ishighrisk'])){{$emailInfo['hastimeout']['ishighrisk']}}@endif" name="sysconfig[email][hastimeout][ishighrisk]" type="text" class="form-control" placeholder="Ishighrisk">
                                </div>
                                <div class="col-xs-2">
                                    <input value="@if(isset($emailInfo['hastimeout']['low'])){{$emailInfo['hastimeout']['low']}}@endif" name="sysconfig[email][hastimeout][low]" type="text" class="form-control" placeholder="Low">
                                </div>
                            </div>
                        </div>
                        {{--启用禁用是系统层面配置env里面配--}}
                        {{--<div class="form-group">
                            <div class="checkbox">
                                <label>
                                    <input name="sysconfig[email][open]" type="checkbox" @if(isset($emailInfo['open'])) checked @endif value="1"> 启用
                                </label>
                            </div>
                        </div>--}}
                        <div class="form-group">
                            <button type="button" id="send-email" class="btn sysconfig-send">发送</button>
                        </div>
                        <input type="hidden" name="type" value="2">
                        {!! csrf_field() !!}
                        <button type="submit" class="btn btn-primary sysconfig-set">提交</button>
                    </form>
                    <form class="navbar-left " @if(old('type')!=3) hidden @endif method="post" action="{{ URL::route('admin.config.set') }}">
                        <div class="form-group">
                            <label for="name">EHR接口开始时间</label>
                            <input value="@if(isset($distributeInfo['start_time'])) {{$distributeInfo['start_time']}} @endif" name="sysconfig[distribute][start_time]" type="text" class="form-control data-picker" placeholder="Start_time">
                        </div>
                        <div class="form-group">
                            <label for="address">EHR接口结束时间</label>
                            <input value="@if(isset($distributeInfo['end_time'])) {{$distributeInfo['end_time']}} @endif" name="sysconfig[distribute][end_time]" type="text" class="form-control data-picker" placeholder="End_time">
                        </div>
                        <input type="hidden" name="type" value="3">
                        {!! csrf_field() !!}
                        <button type="submit" class="btn btn-primary sysconfig-set">提交</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>
@stop
@section('javascript-end')
    <script src="{{env('APP_ROOT')}}/assets/layui/layui.all.js"></script>
<script>
    $(function () {
        //标签页
        $('.nav-tabs li').click(function () {
            var index =$(this).index();
            $(this).siblings().removeClass('active');
            $(this).addClass('active');
            $('.box-body form').hide();
            $('.box-body form').eq(index).show();
        });
        //邮箱页内容操作
        $('.rcp-type').click(function () {
            if ($(this).children().hasClass('row')){
                $('.rcp-default').show();
            }else{
                $('.rcp-default').hide();
            }
        });
        //日历控件
        $('.data-picker').datepicker({
            autoclose: true
        });
        //发邮件
        $('#send-email').click(function () {
            layer.confirm('您确定要现在发邮件吗？', {
                btn: ['确定','取消']
            }, function(){
                $.ajax(
                    {
                        url:"{{route('email.send')}}",
                        method:"GET"
                    }
                ).done(function (data) {
                    if(data.code == 403){
                        layer.msg(data.msg, {icon: 0});
                    }else{
                        $('#send-email').attr('disabled',true);
                        layer.msg('发送成功！', {icon: 1});
                    }
                });
            });
        });
    });
</script>
@endsection
